<?php
/**
 * Created by PhpStorm.
 * Author: 芸签cms www.yunqiancms.com
 * User: sun
 * Date: 2022/6/23
 * Time: 8:42 AM
 */
namespace App\Http\Middleware;

use app\common\routes\CmsRouteDirector;
use app\common\routes\ICmsRoute;
use Illuminate\Support\Str;
use app\common\routes\CmsRouteFactory;

/**
 * 路由自动匹配，不用每次都在配置文件添加
 * Class CmsRoute
 * @package App\Http\Middleware
 */
class CmsRoute
{
    private $routes;

    private $route;

    public function handle($request,\Closure $next)
    {

        $cms_route = CmsRouteFactory::create($request->path());
        // 添加路由
        if ($cms_route instanceof ICmsRoute) {
            (new CmsRouteDirector($cms_route))->setRoute();
        }
        return $next($request);
    }
}